﻿using System;
using System.Reflection;
using java = biz.ritter.javapi;
using biz.ritter.javapi.io;

namespace biz.ritter.javapi.lang
{
    /// <summary>
    /// ParameterizedType
    /// </summary>
    [Serializable]
    public class ParameterizedType
    {
        private readonly Type delegateInstance;

        /// <summary>
        /// ParameterizedType
        /// </summary>
        /// <param name="t"></param>
        public ParameterizedType(Type t)
        {
            this.delegateInstance = t;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="c"></param>
        public ParameterizedType(Class c)
        {
            this.delegateInstance = c.GetType();
        }

        /// <summary>
        /// getActualTypeArguments
        /// </summary>
        /// <returns></returns>
        public Type[] getActualTypeArguments()
        {
            return this.delegateInstance.GetGenericArguments();
        }

        /// <summary>
        /// getRawType
        /// </summary>
        /// <returns></returns>
        public Type getRawType()
        {
            return this.delegateInstance.GetType();
        }



        /// <summary>
        /// User-defined conversion from Type to XmlNode 
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static implicit operator Type(ParameterizedType p)
        {
            return p.delegateInstance;
        }

        //  
        /// <summary>
        /// User-defined conversion from ParameterizedType to Type
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static implicit operator ParameterizedType(Type t)
        {
            return new ParameterizedType(t);
        }
    }
}
